export const POSITION_MAP: any = {
  bottomLeft: {
    originX: 'start',
    originY: 'bottom',
    overlayX: 'start',
    overlayY: 'top',
    offsetX: 0,
    offsetY: -1,
  },
  bottomCenter: {
    originX: 'center',
    originY: 'bottom',
    overlayX: 'center',
    overlayY: 'top',
    offsetX: 0,
    offsetY: -1,
  },
  bottomRight: {
    originX: 'end',
    originY: 'bottom',
    overlayX: 'end',
    overlayY: 'top',
    offsetX: 0,
    offsetY: -1,
  },
  topLeft: {
    originX: 'start',
    originY: 'top',
    overlayX: 'start',
    overlayY: 'bottom',
    offsetX: 0,
    offsetY: 1,
  },
  topCenter: {
    originX: 'center',
    originY: 'top',
    overlayX: 'center',
    overlayY: 'bottom',
    offsetX: 0,
    offsetY: 1,
  },
  topRight: {
    originX: 'end',
    originY: 'top',
    overlayX: 'end',
    overlayY: 'bottom',
    offsetX: 0,
    offsetY: 1,
  },
};

export const ADJUST_POSITION_MAP = [
  POSITION_MAP.bottomLeft,
  POSITION_MAP.bottomRight,
  POSITION_MAP.topLeft,
  POSITION_MAP.topRight,
  POSITION_MAP.bottomCenter,
  POSITION_MAP.topCenter,
];

export function getPosition(connectedPosition): string | undefined {
  const keyList = ['originX', 'originY', 'overlayX', 'overlayY', 'offsetX', 'offsetY'];
  for (const position in POSITION_MAP) {
    if (keyList.every((key): boolean => connectedPosition[key] === POSITION_MAP[position][key])) {
      return position;
    }
  }
  return undefined;
}
